package com.game.raceroom.player.effect
{
	import flash.display.MovieClip;
	import flash.utils.getTimer;
	
	import com.game.raceroom.Room;
	import com.game.raceroom.player.Player;
	public class CrashEffect extends Effect
	{
		private var actor:Player;
		public var x:Number;
		public var y:Number;
		private var room:Room;
		private var crashLv:int;
		private var clist:CrashList;
		private var mc:MovieClip;
		public function CrashEffect(x:Number,y:Number,r:Room,crashLv:int,clist:CrashList,mc:MovieClip)
		{   
			this.crashLv=crashLv;
			this.x=x;
			this.y=y;
			room=r;
 
			startTime=getTimer();
			this.effectType=EFFECT_TYPE_CRASH;
			this.clist=clist;
			this.mc=mc;
			this.mc.visible=false;
            if(crashLv==0){
            	scale=0.2
            	alphDec=0.2;
            }else if(crashLv==1){
            	scale=0.35
            	alphDec=0.15;
            }else if(crashLv==2){
            	scale=0.5;
            	alphDec=0.11;
            }else if(crashLv==3){
            	scale=0.65
            	alphDec=0.08;
            }
            room.acCanvas.addChild(this.mc);
            update();
            room._parents.mainCanvas.sound.playEftSound(1);
			
			 
		}
		var alphDec:Number;
		private var loadOk:Boolean=false;
		var frame:int=0;
		var scale:Number;
         public override function update():Boolean{
         	 
         	mc.scaleX+=scale;
         	mc.scaleY+=scale;
            mc.x=x-room.mapContrl.mapDisp.screen_start_x-mc.width/2;
            mc.y=y-room.mapContrl.mapDisp.screen_start_y-mc.height/2;

 
	        if(frame<mc.totalFrames){
                mc.gotoAndStop(frame);
                mc.visible=true;
                frame++;
	         	
	        }else{
	        	mc.alpha-=alphDec;
	        }
	        if(mc.alpha<=0.4){
	        	if(room.acCanvas.contains(mc))
	        		room.acCanvas.removeChild(mc);
	        	clist.freeMc(mc);
	        	mc=null;
	        	clist=null;
		        valid=false;
	        }
	       

        	 return true;
         }

	}
}